package com.example.spring_gobang.component;

import com.example.spring_gobang.api.Game;
import com.example.spring_gobang.api.Match;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;
@Component
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Autowired
    private Match match;//匹配模块
    @Autowired
    private Game game;//对战模块
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(match,"/findMatch")
                .addInterceptors(new HttpSessionHandshakeInterceptor());
        //把HTTP中session拿到websocket中的session里面
        //进入游戏房间建立连接
        registry.addHandler(game,"/game")
                .addInterceptors(new HttpSessionHandshakeInterceptor());
    }
}
